<?php

##################################################
#
# Copyright (c) 2004-2006 OIC Group, Inc.
# Written and Designed by James Hunt
#
# This file is part of Exponent
#
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################
/**
* Change logs
* June 7, 2011 - trungdt - Add support google map
* 
*/
class contactmodule {
	function name() { return exponent_lang_loadKey('modules/contactmodule/class.php','module_name'); }
	function description() { return exponent_lang_loadKey('modules/contactmodule/class.php','module_description'); }
	function author() { return 'James Hunt'; }
	
	function hasSources() { return true; }
	function hasContent() { return true; }
	function hasViews() { return true; }
	
	function supportsWorkflow() { return false; }
	
	function permissions($internal = '') {
		$i18n = exponent_lang_loadFile('modules/contactmodule/class.php');
		
		return array(
			'administrate'=>$i18n['perm_administrate'],
			'configure'=>$i18n['perm_configure'],
		);
	}
	
	function show($view,$loc = null,$title = '') {
		global $db;
        if (!defined('SYS_FORMS')) include_once(BASE.'subsystems/forms.php');
        exponent_forms_initialize();
        $form = new form();
        if (SITE_USE_CAPTCHA && EXPONENT_HAS_GD) 
        {
            $form->registerBefore('submit',null,'',new htmlcontrol(sprintf($i18n['captcha_description'],'<img src="'.PATH_RELATIVE.'captcha.php" />'),false));
            $form->registerBefore('submit','captcha_string','',new textcontrol('',6,false,6,"",true));
        }
		$contacts = $db->selectObjects('contact_contact',"location_data='".serialize($loc)."'");
		$conf = $db->selectObject('contactmodule_config',"location_data='".serialize($loc)."'");
        
        // fix config HTML in map 
        $conf->location_des = str_replace(array("\r", "\n"),"",$conf->location_des );
        $conf->location_des2 =str_replace(array("\r", "\n"),"",$conf->location_des2 );
        
		$t = new template('contactmodule','_standard',$loc);
		$t->register_permissions(array(
			'administrate','configure'),
			$loc);
		$t->output();
		
		if (isset($conf->location_des))
			$conf->location_des = str_replace(array("\n","\r"),"",$conf->location_des );
		
		$template = new template('contactmodule',$view,$loc);
		$template->assign('contacts',$contacts);
		$template->assign('loc',$loc);
		$template->assign('numContacts',count($contacts));
		$template->assign('moduletitle',$title);
        $template->assign('conf',$conf);
		$template->register_permissions(array(
			'administrate','configure'),
			$loc);
        $template->assign('form_html',$form->toHTML());
		
		$template->output();
	}
	
	function deleteIn($loc) {
		global $db;
		$db->delete('contact_contact',"location_data='".serialize($loc)."'");
	}
	
	function copyContent($oloc,$nloc) {
		global $db;
		foreach ($db->selectObjects('contact_contact',"location_data='".serialize($oloc)."'") as $contact) {
			unset($contact->id);
			$contact->location_data = serialize($nloc);
			$db->insertObject($contact,'contact_contact');
		}
	}
	
	function spiderContent($item = null) {
		// Do nothing, no content
		return false;
	}
}

?>
